package com.ms.log.appender;

import com.ms.log.constant.CommonConstant;
import com.ms.log.event.LogEvent;

import java.io.IOException;


/**
 * @author zdh
 * 简单等控制台输出
 */
public class SimpleConsoleAppender extends AbstractAppender{


    public SimpleConsoleAppender() {}

    public SimpleConsoleAppender(String name) {
        if(name != null && !"".equals(name)){
           super.name = name;
        }
    }

    @Override
    public void doAppend(LogEvent event) {
        try {
            // 设置颜色为红色
            System.out.write(CommonConstant.BLUE.getBytes());
            System.out.write(event.toString().getBytes(charset));
            // 重置颜色
            System.out.write(CommonConstant.RESET.getBytes());
            System.out.flush();  // 刷新输出流，确保立即显示
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
